package com.dyz.LeetCodeforSwordFingerOffer;

import java.util.Stack;

public class MinStack30 {
    /** initialize your data structure here. */
    private Stack<Integer> stack1 = new Stack<>();//主栈
    private Stack<Integer> stack2 = new Stack<>();//辅助栈

    public MinStack30() {

    }

    public void push(int x) {
        stack1.push(x);
        if(stack2.isEmpty()||stack2.peek()>=x){ //注意=号
            stack2.push(x);
        }

    }

    public void pop() {
        if(!stack1.isEmpty()){
            int an = stack1.pop();
            if(an==stack2.peek()){
                stack2.pop();
            }
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int min() {
        return stack2.peek();

    }
}
